//引入异步模块
import myAxios from '@/utils/request'
import type { BaseSaleAttrListModel, SpuImageListModel, SpuInfoModel, SpuListDataModel, SpuSaleAttrListModel } from './model/spuModel'
import type { TrademarkListModel } from './model/trademarkModel'

//枚举存储接口地址

enum Api {
    //获取spu列表
    getSpuListApi = '/admin/product',
    //获取品牌数据
    getTredemarkApi = '/admin/product/baseTrademark/getTrademarkList',
    //获取属性数据
    getBaseSaleAttrApi = '/admin/product/baseSaleAttrList',
    //提交保存spu数据
    saveSpuInfo = '/admin/product/saveSpuInfo',
    //更新spu数据
    updateSpuInfo = '/admin/product/updateSpuInfo',
    //删除spu
    deleteSpu = '/admin/product/deleteSpu/',
    //获取图片列表
    getSpuImageListApi = '/admin/product/spuImageList',
    //获取基础销售属性列表
    getSpuSaleAttrListApi = '/admin/product/spuSaleAttrList'

}

//获取spu列表的接口
export const reqGetgetSpuListData = (page: number, limit: number, category3Id: number) => {
    return myAxios.get<any, SpuListDataModel>(`${Api.getSpuListApi}/${page}/${limit}?category3Id=${category3Id}`)
}

//获取品牌数据
export const reqGetTredemarkListData = () => {
    return myAxios.get<any, TrademarkListModel>(`${Api.getTredemarkApi}`)
}

//获取属性数据
export const reqGetBaseSaleAttrList = () => {
    return myAxios.get<any, BaseSaleAttrListModel>(`${Api.getBaseSaleAttrApi}`)
}

//提交保存spu数据
export const reqSaveSpuInfo = (spuInfo: SpuInfoModel) => {
    return myAxios.post<any, null>(`${Api.saveSpuInfo}`, spuInfo)
}

//更新spu数据
export const reqUpdateSpuInfo = (spuInfo: SpuInfoModel) => {
    return myAxios.post<any, null>(`${Api.updateSpuInfo}`, spuInfo)
}

//删除spu
export const reqDeleteSpu = (spuId: number) => {
    return myAxios.delete<any, null>(`${Api.deleteSpu}/${spuId}`)
}

//获取待编辑的spuInfo中的图片列表
export const reqGetSpuImageListData = (spuId: number) => {
    return myAxios.get<any, SpuImageListModel>(Api.getSpuImageListApi + `/${spuId}`)
}

//获取待编辑的spuInfo中的销售属性及值
export const reqGetSpuSaleAttrListData = (spuId: number) => {
    return myAxios.get<any, SpuSaleAttrListModel>(Api.getSpuSaleAttrListApi + `/${spuId}`)
}
